#! /usr/bin/python3
# -*- coding: utf-8 -*-
# author: maxiao
# date: 2022-12-14 16:10:01
# description: 计算矩形周长、面积并绘制

import turtle

class MyRectangle:
    """矩形类"""
    def __init__(self, x=0, y=0, width=100, height=100):
        self.x = x
        self.y = y
        self.width = width
        self.height = height

    @property
    def get_area(self):
        """获取矩形面积"""
        return self.width * self.height

    @property
    def get_perimeter(self):
        """获取矩形周长"""
        return 2 * (self.width + self.height)

    def draw(self):
        """绘制矩形"""
        turtle.width(5)
        turtle.color('red')
        # 显示箭头
        turtle.showturtle()
        # 移动到起始坐标（顺时针绘制）
        turtle.goto(self.x, self.y)
        # 下笔
        turtle.pendown()
        turtle.goto(self.x + self.width, self.y)
        turtle.goto(self.x + self.width, self.y - self.height)
        turtle.goto(self.x, self.y - self.height)
        turtle.goto(self.x, self.y)


obj = MyRectangle()
print('矩形面积、周长分别为{}，{}'.format(obj.get_area, obj.get_perimeter))
obj.draw()
print('-' * 50)
obj = MyRectangle(20, -30, 200, 150)
print(obj.get_area, obj.get_perimeter)
obj.draw()
